import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:grocery_app_demo/widgets/gap.dart';

import 'logic.dart';

class SelectGoodsPage extends GetView<SelectGoodsLogic> {
  const SelectGoodsPage({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(SelectGoodsLogic());

    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios_new),
          onPressed: () => Get.back(),
        ),
        actions: [
          IconButton(
            onPressed: () {
              controller.callback?.call(controller.getSelectGoodsList());
              Get.back();
            },
            icon: const Icon(Icons.check),
          ),
        ],
        title: Text('商品选择'.tr),
      ),
      body: Column(
        children: [
          Padding(
            padding: gapAll16,
            child: TextField(
              controller: controller.searchCtrl,
              onChanged: (v) => controller.searchWord.value = v,
              decoration: InputDecoration(
                prefixIcon: const Icon(Icons.search),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(50),
                ),
              ),
            ),
          ),
          Expanded(
            child: Obx(() {
              if (controller.finishLoad.isTrue) {
                return ListView(
                  children: controller.buildList(),
                );
              } else {
                return Container(
                  alignment: Alignment.center,
                  child: const CircularProgressIndicator(),
                );
              }
            }),
          ),
        ],
      ),
    );
  }
}